<%@page contentType="text/html; charset=UTF-8" session="false" %>
<%@include  file="/WEB-INF/jspf/import.jspf"%>
<style>
    <c:if test="${msgId eq 0}">
        .condition-list{
            float: left;
            cursor: pointer;
            padding: 2px;
            background: #fff;
            border: 1px solid #ccc;
            margin-right: 5px;
        }
        .condition-list li {
            float: left;
            cursor: pointer;
            padding: 2px 3px;
            background: #fff;
            border: 1px solid #ccc;
            font-size: 12px;
            line-height: 18px;
        }
    </c:if>
    <c:if test="${msgId gt 0}">
        .condition-list{
            float: left;
            padding: 2px;
            background: #fff;
            border: 1px solid #ccc;
            margin-right: 5px;
        }
        .condition-list li {
            float: left;
            padding: 2px 3px;
            background: #fff;
            border: 1px solid #ccc;
            font-size: 12px;
            line-height: 18px;
        }
    </c:if>
</style>
<div class="pageContent">
    <form method="post" action="${ROOT}/admin/message/create.do?" 
          class="pageForm required-validate" onsubmit="return check(this, navTabAjaxDone);">
        <div class="pageFormContent" layoutH="56">
            <h2 class="contentTitle">信息详情</h2>
            <dl class="nowrap">
                <dt>发送时间：</dt>
                <dd>
                    <c:if test="${msgId eq 0}">
                        <input type="text" value="<fmt:formatDate value="${message.sendAt}" pattern="yyyy-MM-dd HH:mm:ss"/>" size="50" name="sendAt" datefmt="yyyy-MM-dd HH:mm:ss" class="date required" readonly="true">
                    </c:if>
                    <c:if test="${msgId gt 0}">
                        <input type="text" value="<fmt:formatDate value="${message.sendAt}" pattern="yyyy-MM-dd HH:mm:ss"/>" size="50" name="sendAt" readonly="true">
                    </c:if>
                </dd>
            </dl>
            <dl class="nowrap">
                <dt>发送范围：</dt>
                <dd style="width: 660px;">
                    <c:if test="${msgId eq 0}">
                        <label><input type="radio" name="sendAll" id="sendAll" ${message.sendAll==1?'checked':'' } value="1">全部会员&nbsp;</label>
                        <label><input type="radio" name="sendAll" id="sendAll" ${message.sendAll==2?'checked':'' }  value="2">会长&nbsp;</label>
                        <label><input type="radio" name="sendAll" id="sendAll" ${message.sendAll==3?'checked':'' } value="3">会长\副会长&nbsp;</label>
                        <label><input type="radio" name="sendAll" id="sendAll" ${message.sendAll==4?'checked':'' }  value="4">认证车主&nbsp;</label>
                        <label><input type="radio" name="sendAll" id="sendAll" ${message.sendAll==5?'checked':'' } value="5">非认证车主</label>
                        </c:if>
                        <c:if test="${msgId gt 0}">
                            <c:choose>
                                <c:when test="${message.sendAll==1}">全部会员</c:when>
                                <c:when test="${message.sendAll==2}">会长</c:when>
                                <c:when test="${message.sendAll==3}">会长\副会长</c:when>
                                <c:when test="${message.sendAll==4}">认证车主</c:when>
                                <c:when test="${message.sendAll==5}">非认证车主</c:when>
                        </c:choose>
                    </c:if>    
                </dd>
            </dl>
            <c:if test="${msgId eq 0}">
                <dl class="nowrap">
                    <dt>发送地区：</dt>
                    <dd><select  name="cityId"  id="cityId" ><option value="" selected>-选择地区-</option></select>
                        <input type="hidden" id="provinceName" name="provinceName" value=""/>
                        <input type="hidden" id="provinceID" name="provinceID" value=""/>
                        <input type="hidden" id="cityName" name="cityName" value=""/>
                        <input type="hidden" id="cityID" name="cityID" value=""/>
                        <input type="hidden" id="areaAndBrandSerialStr" name="areaAndBrandSerialStr" value=""/>
                    </dd>                     
                </dl>
                <dl class="nowrap">
                    <dt>发送品牌：</dt>
                    <dd> 
                        <select id="brandId" name="brandId"><option value="">请选择品牌</option></select>
                        <select name="seriesId" id="seriesId" >
                            <option value="">请选择车系(可不选)</option>
                        </select>
                        <input type="hidden" id="brandName" name="brandName" value=""/>
                        <input type="hidden" id="brandID" name="brandID" value=""/>
                        <input type="hidden" id="seriesName" name="seriesName" value=""/>
                        <input type="hidden" id="seriesID" name="seriesID" value=""/>
                        <span><a class="button" href="javascript:_addAreaAndBrand();"><span>添加</span></a></span> 
                    </dd>
                </dl>
            </c:if>
            <dl class="nowrap" id="areaAndBrandPlace" >
                <dt>已选组合：</dt>
                <dd <c:if test="${msgId eq 0}">id="createSysMsg"</c:if>>
                    <c:if test="${not empty message.comboCndList}">
                        <c:forEach items="${message.comboCndList}" var="cnd">
                            <ul class="condition-list">
                                <c:if test="${cnd.cityId gt 0}">
                                    <li data="city:${cnd.cityId}:${cnd.cityName}">${cnd.cityName}</li>
                                </c:if>
                                <c:if test="${cnd.provinceId gt 0 and cnd.cityId eq 0}">
                                    <li data="province:${cnd.provinceId}:${cnd.provinceName}">${cnd.provinceName}</li>
                                </c:if>
                                <c:if test="${cnd.seriesId gt 0}">
                                    <li data="series:${cnd.seriesId}:${cnd.seriesName}">${cnd.seriesName}</li>
                                </c:if>
                                <c:if test="${cnd.brandId gt 0 and cnd.seriesId eq 0}">
                                    <li data="brand:${cnd.brandId}:${cnd.brandName}">${cnd.brandName}</li>
                                </c:if>
                            </ul>
                        </c:forEach>
                    </c:if>
                </dd>                     
            </dl>
             <c:if test="${msgId eq 0}">
                <dl class="nowrap">
                    <dt>发送星级：</dt>
                    <dd>
                    <select class="textInput" id="clubLevel" name="clubLevel" >
                       <option value="">请选择</option>
                        <c:forEach items="${clubLevels}" var="clubLevel">
                           <option value="${clubLevel.levelId}" >${clubLevel.levelName}</option>
                       </c:forEach>
                       </select>
                        <input type="hidden" id="levelId" name="levelId" value=""/>
                        <input type="hidden" id="levelName" name="levelName" value=""/>
                       <span><a class="button" href="javascript:_addClubLevel();"><span>添加</span></a></span>
                    </dd>                     
                </dl>
            </c:if>
             <dl class="nowrap" id="selectedClubLevel" >
                <dt>已选星级：</dt>
                <dd <c:if test="${msgId eq 0}">id="createSysMsg"</c:if>>
                    
                </dd>                     
            </dl>
             <c:if test="${msgId eq 0}">
                <dl class="nowrap">
                    <dt>发送主题：</dt>
                    <dd>
                    <select class="textInput" id="clubTheme" name="clubTheme" >
                       <option value="">请选择</option>
                        <c:forEach items="${themes}" var="theme">
                           <option value="${theme.themeId}" >${theme.themeName}</option>
                       </c:forEach>
                       </select>
                        <input type="hidden" id="themeId" name="themeId" value=""/>
                        <input type="hidden" id="themeName" name="themeName" value=""/>
                       <span><a class="button" href="javascript:_addTheme();"><span>添加</span></a></span>
                    </dd>                     
                </dl>
            </c:if>
             <dl class="nowrap" id="selectedClubTheme" >
                <dt>已选主题：</dt>
                <dd <c:if test="${msgId eq 0}">id="createSysMsg"</c:if>>
                    
                </dd>                     
            </dl>
            
             <c:if test="${msgId eq 0}">
                <dl class="nowrap">
                    <dt>指定车友会：</dt>
                    <dd>
                       <input type="hidden" name="clubId" id="clubId" value=""/>
                       <input type="text" readonly="readonly" id="clubName" name="clubName"  value="${param.clubName}" onchange="loadContractInfo(this)" suggestFields="clubId,clubName"  lookupGroup=""  autocomplete="off"/>
                       <a class="btnLook" href="${ROOT}/admin/promotion/club/list.do" lookupGroup="">查找车友会</a>
                       <span><a class="button" href="javascript:_addClub();"><span>添加</span></a></span>
                    </dd>                     
                </dl>
            </c:if>
             <dl class="nowrap" id="selectedClub" >
                <dt>已选车友会：</dt>
                <dd <c:if test="${msgId eq 0}">id="createSysMsg"</c:if>>
                    
                </dd>                     
            </dl>
            <dl class="nowrap">
                <dt>发送内容：</dt>
                <dd><textarea rows="5" cols="100" class="textArea required <c:if test="${msgId gt 0}">readonly</c:if>" name="content" ${message.status>0?'readonly':'' }>${message.content}</textarea></dd>
            </dl>
        </div>
        <div class="formBar">
            <ul>
                <c:if test="${msgId eq 0}">
                    <li><div class="buttonActive"><div class="buttonContent"><button onclick="return confirm('确定要保存？（保存后将不可修改）');" type="submit">保存</button></div></div></li>
                </c:if>
                <li><div class="button"><div class="buttonContent"><button class="close" type="button">关闭</button></div></div></li>
            </ul>
        </div>
    </form>
</div>
<c:if test="${msgId eq 0}">
    <script>
        function check(frm, navTabAjaxDone) {
            //提交前设置省份
            var num = $("input[name=sendAll]:checked").length;
            if(num==0){
                alert("请选择消息发送范围。");
                return false;
            }
            if (!validateCallback(frm, navTabAjaxDone)) {
                return false;
            }else{
                return true;
            }
        }
        //添加地区和品牌车系
        function _addAreaAndBrand(){
            var brandID = $("#brandID").val();
            var brandName = $("#brandName").val();
            var seriesName = $("#seriesName").val();
            var seriesID = $("#seriesID").val();
            var provinceName = $("#provinceName").val();
            var provinceID = $("#provinceID").val();
            var cityName = $("#cityName").val();
            var cityID = $("#cityID").val(); 
            var html ="";
            if(cityID != "" || provinceID != ""){
                if(cityID != ""){
                    html += "<li data='city:"+ cityID +":"+cityName+"'>"+ cityName +"</li>";
                }else{
                    html += "<li data='province:"+ provinceID +":"+provinceName+"'>"+ provinceName +"</li>";
                }
            }
            if(seriesID != "" || brandID != "" ){
                if(seriesID != ""){
                    html += "<li data='series:"+ seriesID +":"+seriesName+"'>"+ seriesName +"</li>";
                }else{
                    html += "<li data='brand:"+ brandID +":"+brandName+"'>"+ brandName +"</li>";
                }
            }
            if(html != ""){
                var ul = "<ul class='condition-list' >"+ html + "</ul>";
                var oneCnd = getOneComboCnd($(ul));
                if(getAllComboCnd().indexOf(oneCnd)!=-1){
                    alert('已经选过了');
                }else{
                    $("#areaAndBrandPlace dd").append(ul);
                    $("#areaAndBrandSerialStr").val(getAllComboCnd());
                }
            }else{
                alert("请选择地区或者品牌");
            }
        }
        //车友会地区
        $.getScript("${UCROOT}/intf/area.jsp?tag=cityId&selected=${club.cityId==0?club.provinceId:club.cityId}&defaultCityTips=1");
        //品牌车系
        jQuery.getScript("${ROOT}/js/brand_series.js",function(){
            //车系
            relatedSelect(
            {id:"brandId",url:"http://price.pcauto.com.cn/interface/5_3/brand_json_chooser_v2.jsp?_t=" + new Date().getTime(),node:{root:"brands", value:"id", text:"text",custom:"id"},load:true},
            {id:"seriesId",url:"http://price.pcauto.com.cn/interface/5_3/serial_json_chooser.jsp?brand=",node:{root:"firms", value:"id", text:"text",custom:"id"}});
    
            $("#brandId").change(function(){
                var selectText = $(this).find("option:selected").text();
                var selectId = $(this).find("option:selected").val();
                $("#brandName").val(selectText); 
                $("#brandID").val(selectId); 
                //选完品牌要清车系
                $("#seriesName").val("");
                $("#seriesID").val("");
            });
            $("#seriesId").change(function(){
                var selectText = $(this).find("option:selected").text();
                var selectId = $(this).find("option:selected").val();
                $("#seriesName").val(selectText); 
                $("#seriesID").val(selectId);
            });
   
            $("#areaParentTag_cityId").live('change',function(){
                var selectText = $(this).find("option:selected").text();
                var selectId = $(this).find("option:selected").val();
                $("#provinceName").val(selectText); 
                $("#provinceID").val(selectId); 
                //选完省份要清城市
                $("#cityName").val("");
                $("#cityID").val("");
            });
            $("#cityId").change(function(){
                var selectText = $(this).find("option:selected").text().replace("├","");
                var selectId = $(this).find("option:selected").val();
                $("#cityName").val(selectText); 
                $("#cityID").val(selectId);
            });
    
            $("#createSysMsg .condition-list").live("click",function(){
                $(this).remove();
                $("#areaAndBrandSerialStr").val(getAllComboCnd());
            });
    
    
        });
        function getOneComboCnd($this){
            var strLi ="";
            $this.find("li").each(function(){
                if($(this).attr("data")){
                    strLi += $(this).attr("data")+",";
                }
            });
            if(strLi != ""){
                strLi = strLi.substring(0,strLi.length-1);
            }    
            return strLi;
        }
        //地区和品牌选择组合条件ID拼接
        function getAllComboCnd(){
            var str="";
            $(".condition-list").each(function(){
                str += getOneComboCnd($(this))+";";
            });
            if(str != ""){
                str = str.substring(0,str.length-1);
            }
            return str;
        }
        
        $("#clubLevel").change(function(){
            var selectText = $(this).find("option:selected").text();
            var selectId = $(this).find("option:selected").val();
            $("#levelName").val(selectText); 
            $("#levelId").val(selectId);
        });
        
        
        $("#clubTheme").change(function(){
            var selectText = $(this).find("option:selected").text();
            var selectId = $(this).find("option:selected").val();
            $("#themeName").val(selectText); 
            $("#themeId").val(selectId);
        });
        
        function _addClubLevel(){
            var levelId = $("#levelId").val();
            var levelName = $("#levelName").val();
            var html ="";
            if(levelId != "" && levelName != ""){
                    html += "<li data='clubLevel:"+ levelId +":"+levelName+"'>"+ levelName +"</li>";
            }
            if(html != ""){
                var ul = "<ul class='condition-list' >"+ html + "</ul>";
                var oneCnd = getOneComboCnd($(ul));
                if(getAllComboCnd().indexOf(oneCnd)!=-1){
                    alert('已经选过了');
                }else{
                    $("#selectedClubLevel dd").append(ul);
                    $("#areaAndBrandSerialStr").val(getAllComboCnd());
                }
            }else{
                alert("请星级");
            }
        }
        
        function _addTheme(){
            var themeId = $("#themeId").val();
            var themeName = $("#themeName").val();
            var html ="";
            if(themeId != "" && themeName != ""){
                    html += "<li data='theme:"+ themeId +":"+themeName+"'>"+ themeName +"</li>";
            }
            if(html != ""){
                var ul = "<ul class='condition-list' >"+ html + "</ul>";
                var oneCnd = getOneComboCnd($(ul));
                if(getAllComboCnd().indexOf(oneCnd)!=-1){
                    alert('已经选过了');
                }else{
                    $("#selectedClubTheme dd").append(ul);
                    $("#areaAndBrandSerialStr").val(getAllComboCnd());
                }
            }else{
                alert("请主题");
            }
        }
        
        function _addClub(){
            var clubId = $("#clubId").val();
            var clubName = $("#clubName").val();
            var html ="";
            if(clubId != "" && clubName != ""){
                    html += "<li data='club:"+ clubId +":"+clubName+"'>"+ clubName +"</li>";
            }
            if(html != ""){
                var ul = "<ul class='condition-list' >"+ html + "</ul>";
                var oneCnd = getOneComboCnd($(ul));
                if(getAllComboCnd().indexOf(oneCnd)!=-1){
                    alert('已经选过了');
                }else{
                    $("#selectedClub dd").append(ul);
                    $("#areaAndBrandSerialStr").val(getAllComboCnd());
                }
            }else{
                alert("请选择车友会");
            }
        }
    </script>
</c:if>